<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页面</title>
    <style>
        .tr{
            padding: 20px;     word-break: break-word;
        }
        .auth-btn{
            width: 90%; height: 50px; line-height: 50px; text-align: center; color: #fff;
            font-size: 18px; margin: 50px auto 0 auto; background: #07c160;
        }
    </style>
    <script src="js/jquery.min.js"></script>
    <script src="js/layer/mobile/layer.js"></script>
</head>
<body>
    <div id='params' class="tr"></div>
    <div id='unionid' class="tr"></div>

    <div onclick="test()" class="auth-btn">点击调接口</div>
</body>
</html>
<script>
   
    var appUrl = ''
    if (location.host == 'busi.xueerqin.net') {
        appUrl = 'https://app.xueerqin.net'
    } else {
        appUrl = 'https://tapp.xueerqin.net'
    }

    function getParams() {
        var search = location.search
        search = search.replace('?', '')
        var arr = search.split('&')
        var obj = {}
        for (var item of arr) {
            var list = item.split('=')
            obj[list[0]] = list[1]
        }
    
        return obj
    }

    function getUnionid ({appid, code}) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: appUrl + "/common/api/app/weChatServer/userWechatInfoForComponent",
                data: {
                    appid: appid,
                    code: code
                },
                dataType: "json",
                success: function (data) {
                    $('#unionid').html(JSON.stringify(data))
                    resolve()
                }
            });
        })
    }

    function test(){
        var layerIndex = layer.open({type: 2, shadeClose: false});
        getUnionid(params).then(res => {
            layer.close(layerIndex);
        })
    }

    var params = getParams()
    $('#params').html(JSON.stringify(params))

    
    
   
</script>